<?php
if (!defined('WEB_ROOT')) {
	exit;
}
if (isset($_GET['id']) && $_GET['id'] >0) {
	$id = $_GET['id'];
	$queryString = "&id=$id";
} else {
	$id = 0;
	$queryString = '';
}
	
// for paging
// how many rows to show per page
$rowsPerPage = 5;

$sql = "SELECT tg.id, matg, hotentg, date_format(ngaysinh,'%d-%m-%Y') as ngaysinh, tendv,tgn.nhomnc_id, hinhanh_thumb, hocham, hocvi
        FROM tacgia tg left join tacgia_nhomnc tgn ON tg.id = tgn.tg_id left join donvi dv on tg.dv_id = dv.id
		WHERE tg.hieu_luc = 1
		ORDER BY id desc";
//echo $sql;
$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));
$pagingLink = getPagingLink($sql, $rowsPerPage);   
		
//$groupList = buildGroupOptions($mannc);

?> 
<!-- Begin one column window -->
<div class="onecolumn">
				<div class="header">
					<span>Tác giả</span>
					<div class="switch" style="width:140px">
						<table width="140px" cellpadding="0" cellspacing="0">
						<tbody>
							<tr>
								<td>
									<input name="btnAddGroup" class="middle_switch" type="button" id="btnAddGroup" value="Thêm tác giả"  style="width:140px" onClick="addAuthor()">
								</td>
							</tr>
						</tbody>
						</table>
					</div>
				</div>
				<br class="clear"/>
				<div class="content">
					<form action="processAuthor.php?action=addAuthor" method="post"  name="frmListAuthor" id="frmListAuthor">
					 <!--<table width="100%" border="0" cellspacing="0" cellpadding="2" class="text">
					  <tr>
					   <td align="right">View authors in : 
						<select name="cboGroup" class="box" id="cboGroup" onChange="viewAuthor();">
						 <option selected>All Group</option>
						<?php echo $groupList; ?>
					   </select>
					 </td>
					 </tr>
					</table>-->
					 <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="data">
						  <tr align="center" id="listTableHeader"> 
							   <th>Thông tin tác giả</th>
							   <th width="130">Đơn vị</th>
							   <th width="40">Sửa</th>
							   <th width="40">Xóa</th>
						  </tr>
					  <?php
					$parentId = 0;
					if (dbNumRows($result) > 0) {
						$i = 0;
						
						while($row = dbFetchAssoc($result)) {
							extract($row);
							
							if ($hinhanh_thumb) {
								$hinhanh_thumb = WEB_ROOT . 'images/author/' . $hinhanh_thumb;
							} else {
								$hinhanh_thumb = WEB_ROOT . 'images/no-image-small.png';
							}		
							if ($i%2) {
								$class = 'row1';
							} else {
								$class = 'row2';
							}
							
							$i += 1;
					?>
					  <tr class="<?php echo $class; ?>"> 
						<td><div class="info_img">
							<img src="<?php echo $hinhanh_thumb; ?>">
						</div>
						  <div class="info_detail">
							<ul>
								<li>Mã tác giả:&nbsp;<strong><?php echo $matg; ?></strong></li>
								<li>Tên tác giả:&nbsp;<strong><?php 
								$shortname = shortName($hocvi, $hocham);
								echo  $shortname.$hotentg; ?></strong></li>
								<li>Ngày sinh:&nbsp;<strong><?php echo $ngaysinh; ?></strong></li>
							</ul>
						</div>
						</td>
						<td width="250" align="center"><?php echo $tendv; ?></td>
						<td width="40" align="center"><a href="javascript:modifyAuthor(<?php echo $id; ?>, <?php echo (int)$nhomnc_id; ?>);">Sửa</a></td>
						<td width="40" align="center"><a href="javascript:deleteAuthor(<?php echo $matg; ?>, <?php echo $nhomnc_id; ?>);">Xóa</a></td>
					  </tr>
					  <?php
						} // end while
					?>
					  <tr> 
					   <td colspan="4" align="center">
					   <?php 
					echo $pagingLink;
					   ?></td>
					  </tr>
					<?php	
					} else {
					?>
					  <tr> 
					   <td colspan="4" align="center">No Authors Yet</td>
					  </tr>
					  <?php
					}
					?>
					  <tr> 
					   <td colspan="5">&nbsp;</td>
					  </tr>
					 </table>
					 <p>&nbsp;</p>
					</form>
			</div>
	</div>